package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.entity.Student;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    
    @GetMapping("/listAll")
    public Result<List<Student>> listAll() {
        return Result.success(studentService.findAll());
    }
    
    @GetMapping("/getById/{studentId}")
    public Result<Student> getById(@PathVariable Long studentId) {
        return Result.success(studentService.findById(studentId));
    }
    
    @GetMapping("/getGrades/{studentId}")
    public Result<?> getGrades(@PathVariable Long studentId) {
        return Result.success(studentService.findGradesByStudentId(studentId));
    }
    
    @PostMapping("/add")
    public Result<?> add(@RequestBody Student student) {
        return Result.success(studentService.save(student));
    }
} 